---
title: Direct Token Injection
edit-this-page-url: https://github.com/airweave-ai/airweave/blob/main/fern/docs/pages/direct-token-injection.mdx
subtitle: Create source connections or trigger syncs by supplying OAuth&nbsp;2.0 tokens directly.
slug: direct-token-injection
---

## Use case

If you embed Airweave inside your own product you might already manage OAuth 2.0 tokens for your users.
In that case, you do not want to have to ask them to click through a second consent screen for Airweave.
Airweave therefore allows you to provide existing tokens to Airweave directly, so that

  - Your service owns token storage and rotation.
  - Airweave consumes the tokens solely for data sync.
  - No additional user interaction required.

There are two common scenarios:

1. **Create a new source connection** by sending the access token.
2. **Trigger a sync** on an existing source connection using stored credentials.

The next sections walk you through both flows.

## Create a source connection with your own tokens

Skip the OAuth 2.0 flow entirely by sending your own tokens in the `POST /source-connections` call. You are responsible for acquiring and storing these tokens, Airweave simply uses what you provide.

Creating a source connection with direct tokens looks like this:

<CodeBlocks>
```Python title="Python"
from airweave import AirweaveSDK
from airweave.types import OAuthTokenAuthentication

airweave = AirweaveSDK(api_key="YOUR_API_KEY", base_url="https://api.airweave.ai")

source_connection = airweave.source_connections.create(
    name="Asana connection",
    short_name="asana",
    readable_collection_id="my-collection-id",
    authentication=OAuthTokenAuthentication(
        access_token="YOUR_ACCESS_TOKEN",
    ),
    sync_immediately=True
)
```

```javascript title="Node.js"
import { AirweaveSDKClient } from "@airweave/sdk";

const airweave = new AirweaveSDKClient({apiKey: "YOUR_API_KEY", baseUrl: "https://api.airweave.ai"});

const sourceConnection = await airweave.sourceConnections.create({
    name: "Asana connection",
    shortName: "asana",
    readableCollectionId: "my-collection-id",
    authentication: {
        type: "oauth_token",
        accessToken: "YOUR_ACCESS_TOKEN",
        refreshToken: "YOUR_REFRESH_TOKEN"  // Optional
    },
    syncImmediately: true
});
```

```bash title="cURL"
curl -X POST https://api.airweave.ai/source-connections \
     -H "x-api-key: <apiKey>" \
     -H "Content-Type: application/json" \
     -d '{
  "name": "Asana connection",
  "short_name": "asana",
  "readable_collection_id": "my-collection-id",
  "authentication": {
    "type": "oauth_token",
    "access_token": "YOUR_ACCESS_TOKEN",
    "refresh_token": "YOUR_REFRESH_TOKEN"
  },
  "sync_immediately": true
}'
```
</CodeBlocks>

## Trigger a sync
<Note>The run endpoint uses the stored credentials from the source connection. To use different credentials, create a new source connection with `OAuthTokenAuthentication`.</Note>
By default, Airweave uses the credentials obtained during the initial OAuth 2.0 handshake to run a data synchronization job.

Here is an example:

<CodeBlocks>
```Python title="Python"
from airweave import AirweaveSDK

airweave = AirweaveSDK(api_key="YOUR_API_KEY", base_url="https://api.airweave.ai")

job = airweave.source_connections.run(
    source_connection_id="source_connection_id"
)
```

```javascript title="Node.js"
import { AirweaveSDKClient } from "@airweave/sdk";

const airweave = new AirweaveSDKClient({apiKey: "YOUR_API_KEY", baseUrl: "https://api.airweave.ai"});

const job = await airweave.sourceConnections.run(
    "source_connection_id"
);
```

```bash title="cURL"
curl -X POST https://api.airweave.ai/source-connections/source_connection_id/run \
     -H "x-api-key: <apiKey>" \
     -H "Content-Type: application/json"
```
</CodeBlocks>

### Auth provider connections

Airweave also supports creating source connections through auth providers like Composio and Pipedream. Check out the [Authentication Providers documentation](/auth-providers) to learn more.

If you have an edge case that isn't covered by these features, please let us know at **hello@airweave.ai**.
